<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateWxCard extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //卡券基础信息表，必填字段
        Schema::create('wx_card_bases', function (Blueprint $table) {
            $table->increments('card_base_id')->comment('卡券主键唯一ID');
            $table->string('card_id', 200)->default('')->comment('卡券ID');
            $table->string('card_type', 50)->default('卡券类型,GROUPON|CASH|DISCOUNT|GIFT|GENERAL_COUPON');
            $table->string('logo_url', 150)->default('')->comment('卡券的商户logo，建议像素为300*300');
            $table->string('code_type', 50)->default('')->comment('码型');
            $table->string('brand_name', 50)->default('')->comment('商户名字');
            $table->string('title', 100)->default('')->comment('卡券名');
            $table->string('color', 30)->default('')->comment('券颜色');
            $table->string('notice', 60)->default('')->comment('卡券使用提醒');
            $table->mediumText('description')->comment('卡券使用说明');
            $table->unsignedInteger('sku_quantity')->comment('卡券库存的数量,上限1亿');
            $table->string('date_type', 50)->default('')->comment('使用时间的类型');
            $table->unsignedInteger('fixed_term')->default(0)->comment('自领取后多少天内有效');
            $table->unsignedInteger('fixed_begin _term')->default(0)->comment('自领取后多少天开始生效，领取后当天生效填写0');
            $table->timestamp('begin_timestamp')->nullable()->comment('起用时间');
            $table->timestamp('end_timestamp')->nullable()->comment('结束时间');
            $table->softDeletes();
            $table->timestamps();
        });
        //卡券附加信息，非必填字段
        Schema::create('wx_card_alias', function (Blueprint $table) {
            $table->increments('id')->comment('自增序号');
            $table->unsignedInteger('card_base_id')->default(0)->comment('卡券主键唯一ID');
            $table->unsignedTinyInteger('use_custom_code')->default(0)->comment('是否自定义Code码');
            $table->string('get_custom_code_mode', 30)->default('')->comment('填入 GET_CUSTOM_CODE_MODE_DEPOSIT 表示该卡券为预存code模式卡券');
            $table->string('bind_openid', 60)->default('')->comment('是否指定用户领取');
            $table->string('service_phone', 50)->default('')->comment('客服电话');
            $table->unsignedTinyInteger('use_all_locations')->default(1)->comment('设置本卡券支持全部门店，与location_id_list互斥');
            $table->mediumText('location_id_list')->nullable()->comment('门店位置poiid');
            $table->string('center_title', 30)->default('')->comment('卡券顶部居中的按钮，仅在卡券状 态正常(可以核销)时显示');
            $table->string('center_sub_title', 50)->default('')->comment('显示在入口下方的提示语 ，仅在卡券状态正常(可以核销)时显示。');
            $table->string('center_url', 180)->default('')->comment('顶部居中的url ，仅在卡券状态正常(可以核销)时显示');
            $table->string('center_app_brand_user_name', 180)->default('')->comment('卡券跳转的小程序的user_name，仅可跳转该 公众号绑定的小程序 ');
            $table->string('center_app_brand_pass', 180)->default('')->comment('卡券跳转的小程序的path');
            $table->string('custom_url_name', 50)->default('')->comment('自定义跳转外链的入口名字');
            $table->string('custom_url', 180)->default('')->comment('自定义跳转的URL');
            $table->string('custom_url_sub_title', 50)->default('')->comment('显示在入口右侧的提示语');
            $table->string('custom_app_brand_user_name', 180)->default('')->comment('卡券跳转的小程序的user_name，仅可跳转该 公众号绑定的小程序 ');
            $table->string('custom_app_brand_pass', 180)->default('')->comment('卡券跳转的小程序的path');
            $table->string('promotion_url_name', 50)->default('')->comment('营销场景的自定义入口名称');
            $table->string('promotion_url', 180)->default('')->comment('入口跳转外链的地址链接');
            $table->string('promotion_url_sub_title', 50)->default('')->comment('显示在营销入口右侧的提示语');
            $table->string('promotion_app_brand_user_name', 180)->default('')->comment('卡券跳转的小程序的user_name，仅可跳转该 公众号绑定的小程序 ');
            $table->string('promotion_app_brand_pass', 180)->default('')->comment('卡券跳转的小程序的path');
            $table->unsignedInteger('get_limit')->default(0)->comment('每人可领券的数量限制,不填写默认为50');
            $table->unsignedInteger('use_limit')->default(0)->comment('每人可核销的数量限制,不填写默认为50');
            $table->unsignedTinyInteger('can_share')->default(0)->comment('卡券领取页面是否可分享');
            $table->unsignedTinyInteger('can_give_friend')->default(0)->comment('卡券是否可转赠');
            //各种类型优惠券的不同字段
            $table->unsignedInteger('least_cost')->default(0)->comment('代金券专用，表示起用金额（单位为分）,如果无起用门槛则填0');
            $table->unsignedInteger('reduce_cost')->default(0)->comment('代金券专用，表示减免金额。（单位为分）');
            $table->unsignedInteger('discount')->default(0)->comment('折扣券专用，表示打折额度（百分比）。填30就是七折。');
            $table->mediumText('deal_detail')->nullable()->comment('团购券专用，团购详情');
            $table->mediumText('gift')->nullable()->comment('兑换券专用，填写兑换内容的名称');
            $table->mediumText('default_detail')->nullable()->comment('优惠券专用，填写优惠详情');
            $table->softDeletes();
            $table->timestamps();
            $table->index(['card_base_id','deleted_at'], 'index1');
        });
        //卡券高级信息表
        Schema::create('wx_card_advances', function (Blueprint $table) {
            $table->increments('id')->comment('自增序号');
            $table->unsignedInteger('card_base_id')->default(0)->comment('卡券主键唯一ID');
            $table->string('accept_category', 250)->default('')->comment('指定可用的商品类目');
            $table->string('reject_category', 250)->default('')->comment('指定不可用的商品类目');
            $table->unsignedInteger('least_cost')->default(0)->comment('满减门槛字段');
            $table->string('object_use_for', 300)->default('')->comment('购买xx可用类型门槛');
            $table->unsignedTinyInteger('can_use_with_other_discount')->default(0)->comment('与其他类型共享门槛');
            $table->string('abstract', 200)->default('')->comment('封面摘要简介');
            $table->mediumText('icon_url_list')->nullable()->comment('封面图片列表，仅支持填入一 个封面图片链接');
            $table->mediumText('text_image_list')->nullable()->comment('图文列表，显示在详情内页,二维数组，包含image_url、text字段');
            $table->mediumText('business_service')->nullable()->comment('商家服务类型,数组');
            $table->mediumText('time_limit')->nullable()->comment('使用时段限制，数组，包含type、begin_hour、begin_minute、end_hour、end_minute');
            $table->softDeletes();
            $table->timestamps();
            $table->index(['card_base_id','deleted_at'], 'index1');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('wx_card_bases');
        Schema::dropIfExists('wx_card_alias');
        Schema::dropIfExists('wx_card_advances');
    }
}
